/ Assembly List / LJCTextDataReaderLib / TextDataReader / GetOrdinal

Namespace - LJCTextDataReaderLib


Parameters
name - The field name.

Returns

The field index value.

Syntax

C#
public Int32 GetOrdinal(String name)

Retrieves the index of the data field with the specified name. (DE)

Remarks

Required method if field mapping is used.

Example

C#
using LJCTextDataReaderLib;

// The hasHeadingLine defaults to true if the parameter is not included.
TextDataReader textReader = new TextDataReader();

string[] lines = new string[]
{
  "FirstName, LastName",
  "John, Doe",
  "Jane, Doe"
};

// The field delimiter defaults to "," if the parameter is not included.
textReader.LJCSetLines(lines);

while(textReader.ReadLine())
{
  // Get the current line values as strings.
  int firstNameIndex = textReader.GetOrdinal("FirstName");
  int lastNameIndex = textReader.GetOrdinal("LastName");
  string firstName = textReader.GetString(firstNameIndex);
  string lastName = textReader.GetString(lastNameIndex);
}

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.